package com.ljkj.blockpay.presenter;

import android.content.Context;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.PasswordInter;

/**
 * Created by yp on 2022/3/25
 */
public class PasswordPresenter extends BasePresenterImpl<PasswordInter.PasswordInterView> implements PasswordInter.PasswordInterPresenterView{
    public PasswordPresenter(@NonNull Context context, @NonNull PasswordInter.PasswordInterView view) {
        super(context, view);
    }


    //修改密码
    @Override
    public void changePwd(String newPassword, String oldPassword) {
        JsonMap jsonMap = new JsonMap();
        jsonMap.put("newPassword",newPassword);
        jsonMap.put("oldPassword",oldPassword);
        HttpRequest.JSONPOST(getContext(), ApiToCConfig.USER_ORIGIN_CHANGE_PASSWORD,jsonMap, new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap jsonMap = main.getJsonMap("data");
                    getView().changeSuccess(jsonMap);
                }

            }
        });
    }

    //重置密码
    @Override
    public void resetPwd(String code,String countryCode,String email,String mobile,String tradePwd) {
        JsonMap jsonMap = new JsonMap();
        jsonMap.put("code",code);
        jsonMap.put("countryCode",countryCode);
        jsonMap.put("email",email);
        jsonMap.put("mobile",mobile);
        jsonMap.put("tradePwd",tradePwd);
        HttpRequest.JSONPOST(getContext(), ApiToCConfig.USER_CHANGE_PASSWORD, jsonMap, new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap data = main.getJsonMap("data");
                    getView().resetSuccess(data);
                }
            }
        });
    }
}
